package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"os/exec"
)

func main() {
	type good struct {
		Count, Name, Price, Id, Tid, Img string
	}
	type menu struct {
		Id, Imei, shop_name, consignee_name, consignee_mobile, consignee_address, time, order_sn, long, shop_phone string
		Menu                                                                                                       []good
	}

	var order menu
	cmd := exec.Command("php", "mysql.test.php", "355839022517280") //后面参数都是命令参数
	out, err := cmd.Output()
	if err != nil {
		fmt.Println("Error msg:", err)
	}

	if string(out[6:]) == "error arg" {
		panic(string(out))
		//fmt.Println(string(out))
		//fmt.Println([]byte("error arg"))
	} else if string(out[6:]) == "00" {
		fmt.Println("00")
	} else {
		var c byte = 123
		ind := bytes.IndexByte(out, c)

		err1 := json.Unmarshal(out[ind:], &order)
		if err1 != nil {
			fmt.Println("Can't decode json message  :", err1)
		}

		//fmt.Println(stt)
		fmt.Println(order)
		fmt.Println(order.Id)
		fmt.Println(order.Imei)
		fmt.Println(order.Menu)
		fmt.Println("-------------------:")

		for _, menu := range order.Menu {
			fmt.Println(menu.Count, menu.Name)
		}
	}

}
